var jsonserver="http://192.168.6.52:8090/",versionFlag="jx";//北京,江西版本区分标识
//jsonserver='http://61.50.254.57/server/';
jsonserver='http://118.212.184.127/newnp/';
var versionNum="1.40";
/*var b_url = self.location.href,jsonserver;
var hosturl = b_url.substr(0,b_url.indexOf("/",8));
jsonserver = hosturl + "/server/";*/
var url = document.URL,rp;
function trim(str){ //删除左右两端的空格
　　 return str.replace(/(^\s*)|(\s*$)/g, "");
}
window.onload=function(){ 
	if(document.documentElement.scrollHeight <= document.documentElement.clientHeight) { 
		bodyTag = document.getElementsByTagName('body')[0]; 
	} 
	setTimeout(function() { 
		window.scrollTo(0, 1) ;
	}, 1); 
	
		

}
$(document).ready(function(){
	$("body").css("overflow","scroll");
	//调用登录验证
	loginCheck();
	if(versionFlag=="jx"){
		$("title").text("星火平台");
		var linkShort='<link id="shortIcon" rel="shortcut icon" href="images/shorcut.png">'+
			'<link href="images/pasteDesktop.png" rel="apple-touch-icon-precomposed">';
		$(linkShort).insertAfter("title");
	}
    //适配
    if(detectDeviceType()=="Apple"){
        $("#viewport").attr("content","width=640,initial-scale=0.5, maximum-scale=0.5, minimum-scale=0.5,user-scalable=no");
		
    }

    var headerTds=$(".header table td").css("color","#fff");
	$.each(headerTds,function(i,items){
		if(i%2==0){
			$(items).css({"font-size":"28px","font-family":"微软雅黑"});
			$(items).attr("width","19%");
		}else{
			$(items).css("font-size","42px");
		}
	});
	//使用返回,跳至菜单页面,将相应的项目选中
	var pname=window.location.pathname;
	if(url != null && url.indexOf("businessRecommend")==-1
		&& url.indexOf("xiaoxi")==-1 && url.indexOf("message")==-1 && url.indexOf("business3G")==-1 
		&& url.indexOf("businessDetail")==-1 && url.indexOf("dingdanxq")==-1 
		&& url.indexOf("shequ.html")==-1 && url.indexOf("commissionxq")==-1 && url.indexOf("xieyi")==-1 && url.indexOf("newuser_login")==-1
		&& url.indexOf("yongjinzhengce.html")==-1 && url.indexOf("taocanxiangqing")==-1 && url.indexOf("huodongxiangqing")==-1
		&& url.indexOf("user_help")==-1){
		$(".menuTd").text("菜单").bind("click",function(){
			//获取页面名称
			var pstrs=pname.split("/");
			pname=pstrs[pstrs.length-1].replace(".html","");
			pname=pname=="userInfoAdd"?"userInfo":pname;
			window.location.href="menu.html?rp="+pname;
		});
	}
	if($(".menuTd").text()=="返回" && url.indexOf("businessRecommend")==-1 && url.indexOf("message")==-1){
		
		$(".menuTd").bind("click",function(){
			window.history.go(-1);
		});
	}
	
});
function detectDeviceType(){
    var isIphone =navigator.userAgent.indexOf("iPhone") != -1;
    var isIpod = navigator.userAgent.indexOf("iPod") != -1 ;
    var isIpad = navigator.userAgent.indexOf("iPad") != -1 ;
    var isMS = navigator.userAgent.indexOf("Trident") != -1 ;
    var isAndroid = navigator.userAgent.indexOf("Linux") != -1 ;
    var isIos = isIphone || isIpod || isIpad ;
    var a;
    if(isIphone+isIpod+isIpad+isAndroid+isMS==0){a="other";}else if(isMS){a = "winp"}else{a=isIos?"Apple":"Android";}
    return a;
} 
//注销
function clearCookie(){
	jConfirm("是否立刻注销。",'注销',function(e){
		if(e==true){
			window.location.href="login.html?autologin=false";
			clearC();
		}
	});
}
function clearC(){
	 $.cookie("NP_INFO_ID",null,{path:"/",expires:-1});
	 $.cookie("NP_INFO_TELNO",null,{path:"/",expires:-1});
	 $.cookie("newuser",null,{path:"/",expires:-1});
	 $.cookie("U_KEY",null,{path:"/",expires:-1});
	 $.cookie("IS_BJ_LT",null,{path:"/",expires:-1});
	 $.cookie("LT_VIP",null,{path:"/",expires:-1});
	 $.cookie("Ukey",null,{path:"/",expires:-1});
	 $.cookie("email",null,{path:"/",expires:-1});
	 try{
		 localStorage.clear(fid);
		}catch (e){}
	 
	 
}
/*登录验证.ukey为空直接跳转到登录页面*/
function loginCheck(){
	var uk=$.cookie("U_KEY");
	
	if(url != null && url.indexOf("login")==-1){
		if(uk==null || uk=="" || uk.length!=32){
			clearC();
			localStorage.clear();
			document.location="login.html?autologin=false";
		}
	}
	
}





function email_test(str){
	var i,flag=0;
	var at_symbol=0;
	//“@”检测的位置
	var dot_symbol=0;
	//“.”检测的位置

	for (i=1;i<str.length;i++)
	if(str.charAt(i)=='@')
	  {
	  at_symbol=i;
	  break;
	  }
	//检测“@”的位置

	if(at_symbol==str.length-1 || at_symbol==0)
	return(2);
	//没有邮件服务器域名

	if(at_symbol<3)
	return(3);
	//帐号少于三个字符

	if(at_symbol>19 )
	return(4);
	//帐号多于十九个字符

	for(i=1;i<at_symbol;i++)
	if(char_test(str.charAt(i))==0 && spchar_test(str.charAt(i))==0)
	  return (5);
	for(i=at_symbol+1;i<str.length;i++)
	if(char_test(str.charAt(i))==0 && spchar_test(str.charAt(i))==0)
	  return (5);
	//不能用其它的特殊字符 
	 
	for(i=at_symbol+1;i<str.length;i++)
	if(str.charAt(i)=='.') dot_symbol=i;
	for(i=at_symbol+1;i<str.length;i++)
	if(dot_symbol==0 || dot_symbol==str.length-1)
	//简单的检测有没有“.”，以确定服务器名是否合法
	return (6);
	 
	return (0);
	//邮件名合法
} 
function char_test(chr)
		//字符检测函数
		{
			var i;
			var smallch="abcdefghijklmnopqrstuvwxyz";
			var bigch="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
			for(i=0;i<26;i++)
			if(chr==smallch.charAt(i) || chr==bigch.charAt(i))
			  return(1);
			return(0);
			}
	
			function spchar_test(chr)
			//数字和特殊字符检测函数
			{
			var i;
			var spch="_-.0123456789";
			for (i=0;i<13;i++)
			  if(chr==spch.charAt(i))
			  return(1);
			return(0);
		}
//点返回按钮时回到前一个页面
function btn_back_click(){
 history.back(-1);
}


 $.natureajax = function(option){
	//contentType : "application/x-www-form-urlencoded; charset=utf-8",
	$.ajax({
		url:option.url,
		contentType : "application/x-www-form-urlencoded; charset=UTF-8",
		type:"GET",
		data:option.data,
		dataType:'jsonp',
		success:function(data){
			try{
				if(data[0].info.indexOf("key error")>-1){
					location.href="login.html";
				}
			}catch(e){}
			if(option.success){
				option.success(data);
			}
		},
		error:function(){
			if(option.error){
				option.error();
			}
		}
	});
  }
